﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.ComponentModel;

namespace Project
{
    /// <summary>
    /// This is the main menu
    /// </summary>
    /// 
    //lots o' stuff from http://www.alecjacobson.com/weblog/?p=539


    public class WinScreen : EngineState
    {
        Engine engine;
        ContentManager content;
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        SpriteFont statsFont;
        SoundManager sm;

        //mouse pressed and mouse just pressed
        bool mpressed, prev_mpressed = false;
        //mouse location in window
        int mx, my;
        double frame_time;

        enum BState
        {
            HOVER,
            UP,
            JUST_RELEASED,
            DOWN
        }
        const int NUMBER_OF_BUTTONS = 0,
            NUMBER_OF_LEVELS = 4,
            BACK_BUTTON_INDEX = 0,
            BUTTON_HEIGHT = 64,
            BUTTON_WIDTH = 300;
        Color background_color;



        public void initialize(Engine e, ContentManager cm, GraphicsDeviceManager gdm)
        {
            engine = e;
            content = cm;
            graphics = gdm;
            sm = new SoundManager(cm);
            Vector2 viewportSize = new Vector2(graphics.GraphicsDevice.Viewport.Width,
                graphics.GraphicsDevice.Viewport.Height);
            // starting x and y locations to stack buttons
            // vertically in the middle of the screen

            engine.setMouseVisible(true);
            background_color = new Color(30, 30, 30);
        }

        public void destroy()
        {
        }

        public void loadContent()
        {
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            statsFont = content.Load<SpriteFont>("fonts/BigArial");
            //sm.playSound("sounds\\winTheme");

        }

        public void update(GameTime gameTime)
        {
            if ((Keyboard.GetState().IsKeyDown(Keys.Escape)))
                engine.exit();
            else if ((Keyboard.GetState().IsKeyDown(Keys.Enter)))
            {
                engine.setState(new MainMenu());
            }
            else if ((Keyboard.GetState().IsKeyDown(Keys.Space)))
            {
                engine.setState(new MainMenu());
            }


        }

        public void draw(GameTime gameTime)
        {

            graphics.GraphicsDevice.Clear(background_color);

            spriteBatch.Begin();

            float xOffsetText, yOffsetText;
            Vector2 viewportSize = new Vector2(graphics.GraphicsDevice.Viewport.Width,
                graphics.GraphicsDevice.Viewport.Height);
            Vector2 strCenter;

            graphics.GraphicsDevice.Clear(Color.Black);

            xOffsetText = yOffsetText = 0;
            Vector2 strInstructionsSize =
                statsFont.MeasureString("YOU WIN");
            Vector2 strPosition;
            strCenter = new Vector2(strInstructionsSize.X / 2,
                strInstructionsSize.Y / 2);

            yOffsetText = (viewportSize.Y / 2 - strCenter.Y);
            xOffsetText = (viewportSize.X / 2 - strCenter.X);
            strPosition = new Vector2((int)xOffsetText, (int)yOffsetText);

            spriteBatch.DrawString(statsFont, "YOU WIN",
                strPosition, Color.White);


            spriteBatch.End();
        }







    }
}
